/*
 * Copyright (c) Ulrich Hilger, http://dev.uhilger.de, all rights reserved.
 *
 * Published under the terms and conditions of the Apache License 2.0,
 * see http://www.apache.org/licenses/LICENSE-2.0
 */

package de.uhilger.servicehub.model;

import java.sql.SQLException;
import java.util.List;

/**
 * This interface needs to be implemented by classes that model a UserStore
 * of application ServiceHub.
 *
 * @author Ulrich Hilger, <a href="http://dev.uhilger.de" target="_blank">http://dev.uhilger.de</a>
 * @author Published under the terms and conditions of
 * the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License 2.0</a>
 */
public interface UserStore {

  // --- Users

  /**
   * Get all users in store
   * @return  a list of all users
   * @throws Exception
   */
  public List<User> getUsers() throws Exception;

  /**
   * Create a new user
   * @param user  the user to create
   * @return  the created user
   * @throws Exception
   */
  public Object createUser(User user) throws Exception;

  /**
   * Store changes for an exisitng user
   * @param userId  id of user to change
   * @param user  the changed user data
   * @throws Exception
   */
  public void storeUser(Object userId, User user) throws Exception;

  /**
   * Remove a user from the store
   * @param userId  id of user to remove
   * @throws Exception
   */
  public void deleteUser(Object userId) throws Exception;

  /**
   * Get the roles of a user
   * @param userId id of user to get the roles of
   * @return  a list of all roles of the given user
   * @throws Exception
   */
  public List<Role> getUserRoles(Object userId) throws Exception;

  /**
   * Grant a role to a user
   * @param userId  id of user to grant role to
   * @param roleId  id of role to grant
   * @throws Exception
   */
  public void addUserRole(Object userId, Object roleId) throws Exception;

  /**
   * Revoke a role
   * @param userId  id of user to revoke role from
   * @param roleId  id of role to revoke
   * @throws Exception
   */
  public void removeUserRole(Object userId, Object roleId) throws Exception;



  // --- Roles

  /**
   * Create a role
   * @param role  the role to create
   * @return  the created role
   * @throws Exception
   */
  public Object createRole(Role role) throws Exception;

  /**
   * Store changes to a role
   * @param roleId  id of role to change
   * @param role  the changed role to store
   * @throws Exception
   */
  public void storeRole(Object roleId, Role role) throws Exception;

  /**
   * Remove a role from the store
   * @param roleId  id of role to remove
   * @throws Exception
   */
  public void deleteRole(Object roleId) throws Exception;

  /**
   * Get a list of all roles in the store
   * @return  hte list of roles
   * @throws Exception
   */
  public List<Role> getRoles() throws Exception;

  /**
   * Get a list of roles a user does not have
   * @param userId  id of user to get unassigned roles for
   * @return  the list of roles, the given user does not have
   * @throws Exception
   */
  public List<Role> getUnassignedRoles(Object userId) throws Exception;

  public void setBase(String base);
  public String getPort();
  public String getBase();
  public void setUserStorageName(String nmae);
  public String getUSerStorageName();
  public void close() throws SQLException;

  public void setDbUser(String dbUser);

  public void setDbPassword(String dbPass);

  public void changePassword(String dbPass);

}
